<template>
  <div id="tab-control">
    <div class="tab-control-item" v-for="(item,index) in titles" @click="itemClick(index)">
      <span :class="{active : currentIndex === index}">{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "TabControl",
    props: {
      titles:{
        type: Array,
        default(){
          return [];
        }
      }
    },
    data(){
      return {
        currentIndex: 0
      };
    },
    methods: {
      itemClick(index){
        this.currentIndex = index;
        this.$emit("controlClick",index);
      }
    }
  }
</script>

<style scoped>
  #tab-control{
    display: flex;
    text-align: center;
    width: 100%;
    background-color: white;
    height: 40px;
    font-size: 15px;
    align-items: center;
  }
  #tab-control .tab-control-item{
    line-height: 40px;
    flex: 1;
  }
  .tab-control-item .active{
    color: var(--color-tint);
    padding: 3px;
    border-bottom: 3px solid red;
  }
</style>